// 配置 seo

import {NextSeo} from "next-seo";
import {useRouter} from "next/router";
import Head from "next/head";

// 工具类
import {AppConfig} from "@/configs/appConfig";

type IMetaProps = {
    title: string;
    description: string;
    keywords: string;
    canonical?: string;
};

const Meta = (props: IMetaProps) => {
    const router = useRouter();
    return (
        <>
            <Head>
                <meta charSet="UTF-8" key="charset" />
                <meta name="viewport" content="width=device-width,initial-scale=1" key="viewport" />
                <link
                    rel="apple-touch-icon"
                    href={`${router.basePath}/apple-touch-icon.png`}
                    key="apple"
                />
                <link
                    rel="icon"
                    type="image/png"
                    sizes="32x32"
                    href={`${router.basePath}/favicon-32x32.png`}
                    key="icon32"
                />
                <link
                    rel="icon"
                    type="image/png"
                    sizes="16x16"
                    href={`${router.basePath}/favicon-16x16.png`}
                    key="icon16"
                />
                <link rel="icon" href={`${router.basePath}/favicon.ico`} key="favicon" />
                <meta name="keywords" content={props.keywords}></meta>
                {/* <script dangerouslySetInnerHTML={{
                    __html: `var _hmt = _hmt || [];
                    (function() {
                      var hm = document.createElement("script");
                      hm.src = "https://hm.baidu.com/hm.js?252beb8d9767bf4bd5e9c25b8f1ae9a2";
                      var s = document.getElementsByTagName("script")[0]; 
                      s.parentNode.insertBefore(hm, s);
                    })();`}} /> */}
            </Head>
            <NextSeo
                title={props.title}
                description={props.description}
                canonical={props.canonical}
                openGraph={{
                    title: props.title,
                    description: props.description,
                    url: props.canonical,
                    locale: AppConfig.locale,
                    site_name: AppConfig.site_name,
                }}
            />
        </>
    );
};

export {Meta};
